<?php
namespace Common\Model;
use Common\Common\Model;

class CustomerModel extends Model {
    
    protected $tableName = 'Customer';

    protected $tablePrimary = "ID";

    public function fetchByUsername($key){
        $result = $this->where(['Username'=>$key])->find();
        if($result == null) return null;
        return $this->make($result);
    }

    /**
     * 用户登录标记
     * @param CustomerObject $user
     */
    public function login(CustomerObject $user){
        $_SESSION['Customer'] = $user->ID;
    }

    /**
     * 获取当前登录用户
     * @return CustomerObject|null
     */
    public function currentUser(){
        if(empty($_SESSION['Customer'])) return null;
        return $this->fetch($_SESSION['Customer']);
    }



    public function getCollects(){
        /** @var CollectModel $collect */
        $collect = D('Collect');
    }
    
    public function getCats(){
        
    }
    
    public function getCatsCount(){
        
    }

    
}